package com.xinqi.modules.course.classmenu.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.enums.CourseContentTypeEnum;
import com.xinqi.modules.course.classmenu.client.ClassMenuClient;
import com.xinqi.modules.course.classmenu.dto.req.ClassMenuQueryDTO;
import com.xinqi.modules.course.classmenu.dto.rsp.ClassMenuResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 课程中版块设置表降级处理
 *
 * @author: linkai
 * @date: 2023/10/25
 */
@Slf4j
@Component
public class ClassMenuFallbackFactory implements FallbackFactory<ClassMenuClient> {

    @Override
    public ClassMenuClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new ClassMenuClient() {
            @Override
            public R<PageInfo<ClassMenuResultDTO>> page(ClassMenuQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<ClassMenuResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Void> checkShowCourseContent(Long classId, CourseContentTypeEnum contentType) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

        };
    }
}
